package com.tuyrt.hi.ui.refresh;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.tuyrt.hi.library.util.HiDisplayUtil;

/**
 * author: Administrator on 2021/4/30.
 * desc:
 */
public abstract class HiOverView extends FrameLayout {

    public enum HiRefreshState {
        STATE_INIT, // 初始态
        STATE_VISIBLE, // Header展示出来的状态
        STATE_OVER, // 超出可刷新距离的状态
        STATE_REFRESH, // 刷新中的状态
        STATE_OVER_RELEASE, // 超出刷新位置松开手后的状态
    }

    protected HiRefreshState mState = HiRefreshState.STATE_INIT;
    /**
     *  触发下拉刷新 需要的最小高度
     */
    public int mPullRefreshHeight;

    /**
     *  最小阻尼
     */
    public float minDamp = 1.6f;

    /**
     *  最大阻尼
     */
    public float maxDamp = 2.2f;

    public HiOverView(@NonNull Context context) {
        super(context);
        preInit();
    }

    public HiOverView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        preInit();
    }

    public HiOverView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        preInit();
    }

    protected void preInit() {
        mPullRefreshHeight = HiDisplayUtil.dp2px(66, getResources());
        init();
    }

    /**
     * 初始化
     */
    public abstract void init();

    /**
     * @param scrollY
     * @param pullRefreshHeight
     */
    protected abstract void onScroll(int scrollY, int pullRefreshHeight);

    /**
     * 显示 Overview
     */
    public abstract void onVisible();

    /**
     * 超过Overlay，释放就会加载
     */
    protected abstract void onOver();

    /**
     * 开始刷新
     */
    public abstract void onRefresh();

    /**
     * 刷新结束
     */
    public abstract void onFinished();

    public HiRefreshState getState() {
        return mState;
    }

    public void setState(HiRefreshState state) {
        this.mState = state;
    }
}
